package com.ease.database.initializer;

import java.util.StringTokenizer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import com.ease.common.util.Detect;
import com.ease.common.util.FileUtil;
import com.ease.common.vo.MapParameter;
import com.ease.dao.JdbcTemplateDataAccessObject;
import com.obas.test.ApplicationContextUserContextTest;

/**
 * @author nathanleewei
 *
 */
public class LocationInitializer extends ApplicationContextUserContextTest {

	@Autowired
	JdbcTemplateDataAccessObject jdbcTemplateDataAccessObject;

	// @Test
	public void test() {
		String string = FileUtil.readClassPathResourceToString(LocationInitializer.class, "areano.txt");

		String[] rows = StringUtils.delimitedListToStringArray(string, "\r\n");

		if (null != rows) {
			for (String row : rows) {
				StringTokenizer stringTokenizer = new StringTokenizer(row, "\t");

				MapParameter parameter = new MapParameter();
				parameter.put("code", Detect.trim(stringTokenizer.nextToken()));
				parameter.put("name", Detect.trim(stringTokenizer.nextToken()));
				jdbcTemplateDataAccessObject.create("INSERT INTO C_LOCATION(ID, CODE, NAME)VALUES(SEQ_C_LOCATION.NEXTVAL, :code, :name)", parameter);
			}
		}

	}

}
